package com.jk.customer.service.impl;

import com.jk.customer.dao.SellerWzyDao;

import com.jk.customer.entity.*;
import com.jk.customer.service.SellerWzyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SellerWzyServiceImpl implements SellerWzyService {
    @Autowired
    private SellerWzyDao sellerWzyDao;

    /**
     * wzy
     * 查询询价单列表
     * @param product
     * @param session
     * @return
     */
    @Override
    public List<ProductEntity> getCommonTable(ProductEntity product, HttpSession session) {
        UserEntity user = (UserEntity) session.getAttribute("user");
        List<ProductEntity> commonTable = sellerWzyDao.getCommonTable(product);
        for (ProductEntity pro : commonTable) {
            OfferFormEntity offer = sellerWzyDao.getProductByUserId(user.getUserId(),pro.getProductId());
            OrderFormEntity order = sellerWzyDao.getOrderByUserId(user.getUserRealName(),pro.getProductId());

            if (offer == null){
                pro.setEstimatePirceType(0); //待报价
            }else{
                        pro.setEstimatePirceType(1); //已报价
            }

            if (order == null) {
                pro.setPicketageStatus(0);
            }else{
                pro.setPicketageStatus(1);
            }

        }

        return commonTable;
    }

    /**
     * 动态下拉  查询询价状态类型
     */
    @Override
    public List<StatusTypeEntity> getPriceSelectClass() {
        return sellerWzyDao.getPriceSelectClass();
    }

    /**
     * 查询详情页面
     * @param session
     * @return
     */
    @Override
    public Map wzyforgetparticulars(HttpSession session) {
        UserEntity user = (UserEntity) session.getAttribute("user");
        Object productId = session.getAttribute("productId");
        ProductEntity product = sellerWzyDao.getParticulars(productId);
       /* session.setAttribute("showPriceId",product.getQueryPriceId());*/
        Map map = new HashMap();
        map.put("user",user);
        map.put("product",product);
        return map;
    }

    /**
     * 查询询图列表
     * @param product
     * @param session
     * @return
     */
    @Override
    public List<ProductEntity> getPictureTable(ProductEntity product, HttpSession session) {
        UserEntity user = (UserEntity) session.getAttribute("user");
        List<ProductEntity> pictureTableList = sellerWzyDao.getPictureTable(product);
        for (ProductEntity pro : pictureTableList){
            PictureFile file = sellerWzyDao.getPictureFileById(user.getUserId(),pro.getProductId());
            PictureFile file2 = sellerWzyDao.getPictureFileStart(user.getUserId(),pro.getProductId());
            if (file == null) {
                pro.setFileStatus(0);
            }else{
                pro.setFileStatus(1);
            }
            if (file2 == null) {
                pro.setFileStatusTo(0);
            }else{
                pro.setFileStatusTo(1);
            }
        }
        return pictureTableList;
    }

    /**
     * 动态下拉  查询询图状态类型
     * @return
     */
    @Override
    public List<StatusTypeEntity> getPictureSelectClass() {
        return sellerWzyDao.getPictureSelectClass();
    }

    /**
     * 查询询图详情页面
     *
     * @param pid
     * @param
     * @return
     */
    @Override
    public Map wzyForGetPictureParticulars(String pid) {
        Map map = new HashMap();
        ProductEntity product = sellerWzyDao.getPictureParticulars(pid);
        map.put("product",product);
        return map;
    }

    /**
     * 放弃报价
     * @param productId
     * @param session
     */
    @Override
    public void giveUpById(String productId, HttpSession session) {
        UserEntity user = (UserEntity) session.getAttribute("user");
        sellerWzyDao.giveUpById(productId,user.getUserId());
    }


}
